/****************************************************************
 *                                                              *
 *  mco.h                                                       *
 *                                                              *
 *  This file is a part of the eXtremeDB source code.           *
 *                                                              *
 *  Copyright (c) 2001-2012 McObject LLC. All Rights Reserved.  *
 *                                                              *
 *  eXtremeDB runtime public definitions and static API         * 
 *                                                              *
 ****************************************************************/
#ifndef MCO_MCO_H__
    #define MCO_MCO_H__

    #ifdef __cplusplus
        extern "C"
        {
        #endif 

	#ifdef _INTEGRITY
	#include "mcosmint.h"
	#endif

        #include "mcospec.h"

        typedef enum MCO_RET_E_ /* return codes */
        {
            /* status codes */
            MCO_S_OK                           = 0,   /* success  */
            MCO_S_BUSY                         = 1,   /* the instance is busy */
            MCO_S_NOTFOUND                     = 10,  /* search operation failed */
            MCO_S_CURSOR_END                   = 11,  /* cursor cannot be moved */
            MCO_S_CURSOR_EMPTY                 = 12,  /* no objects in index */
            MCO_S_DUPLICATE                    = 13,  /* index restriction violated (duplicate) */
            MCO_S_EVENT_RELEASED               = 14,  /* waiting thread was released */
            MCO_S_DEAD_CONNECTION              = 15,  /* database connection is invalid */
            MCO_S_NULL_VALUE                   = 16,  /* field has NULL value */

            /* error codes and code bases */
            MCO_E_CORE                         = 50,
            MCO_E_INVALID_HANDLE               = 51,  /* normally invalid handle causes a fatal error. */
            MCO_E_NOMEM                        = 52,  /* no memory */
            MCO_E_ACCESS                       = 53,  /* attempt to use a read only transaction for a write operation */
            MCO_E_TRANSACT                     = 54,  /* transaction is in the error state */
            MCO_E_INDEXLIMIT                   = 55,  /* vector index out of bounds */
            MCO_E_EMPTYVECTOREL                = 56,  /* vector element was not set (at given index) */
            MCO_E_UNSUPPORTED                  = 57,  /* unsupported call  */
            MCO_E_EMPTYOPTIONAL                = 58,  /* an optional structure has not been set */
            MCO_E_EMPTYBLOB                    = 59,  /* attempt to read a null blob  */
            MCO_E_CURSOR_INVALID               = 60,  /* cursor is not valid */
            MCO_E_ILLEGAL_TYPE                 = 61,  /* search by oid: type is not expected */
            MCO_E_ILLEGAL_PARAM                = 62,  /* invalid paramter; e.g. illegal search operation type */
            MCO_E_CURSOR_MISMATCH              = 63,  /* cursor type and object type are incompatible */
            MCO_E_DELETED                      = 64,  /* attempt to update an object deleted in the current transaction */
            MCO_E_LONG_TRANSACTON              = 65,  /* transaction length is greater then MCO_TRN_MAXLENGTH */
            MCO_E_INSTANCE_DUPLICATE           = 66,  /* duplicate database instance */
            MCO_E_UPGRADE_FAILED               = 67,  /* transaction upgrade failed; a write transactions is in progress  */
            MCO_E_NOINSTANCE                   = 68,  /* database instance is not found */
            MCO_E_OPENED_SESSIONS              = 69,  /* failed to close database because it has open connections */
            MCO_E_PAGESIZE                     = 70,  /* page size is not acceptable */
            MCO_E_WRITE_STREAM                 = 71,  /* write stream failure */
            MCO_E_READ_STREAM                  = 72,  /* read stream failure  */
            MCO_E_LOAD_DICT                    = 73,  /* attempt to load an incompatible dictionary in db_load */
            MCO_E_LOAD_DATA                    = 74,  /* attempt to load a corrupted image in db_load */
            MCO_E_VERS_MISMATCH                = 75,  /* version mismatch */
            MCO_E_VOLUNTARY_NOT_EXIST          = 76,  /* voluntary index has not been created */
            MCO_E_EXCLUSIVE_MODE               = 77,  /* attempt to open a database that is already open in the exclusive mode */
            MCO_E_MAXEXTENDS                   = 78,  /* maximum number of extends reached */
            MCO_E_HIST_OBJECT                  = 79,  /* operation is illegal for the older version of the object */
            MCO_E_SHM_ERROR                    = 80,  /* failed attempt to create/attach to shared memory */
            MCO_E_NOTINIT                      = 81,  /* runtime was not initialized */
            MCO_E_SESLIMIT                     = 82,  /* sessions number limit reached */
            MCO_E_INSTANCES_LIMIT              = 83,  /* too many instances */
            MCO_E_MAXTRANSSIZE_LOCKED          = 84,  /* the maximum size of transaction cannot be changed */
            MCO_E_DEPRECATED                   = 85,  /* obsolete feature */
            MCO_E_NOUSERDEF_FUNCS              = 86,  /* DB has userdef indexes defined, but no custom functions registered */
            MCO_E_CONFLICT                     = 87,  /* MVCC conflict */
            MCO_E_INMEM_ONLY_RUNTIME           = 88,  /* there are persisten classes in the schema but runtime in-memory only */
            MCO_E_ISOLATION_LEVEL_NOT_SUPPORTED= 89,  /* requested isolation level is not supported */
            MCO_E_REGISTRY_UNABLE_CREATE_CONNECT=90,  /* unable to create a new registry */
            MCO_E_REGISTRY_UNABLE_CONNECT      = 91,  /* unable to connect to an existing registry */
            MCO_E_REGISTRY_INVALID_SYNC        = 92,  /* invalid sync in the registry detected */
            MCO_E_MDEV_RUNTIME_START           = 93,  /* unable to initialise memory device for the registry */
            MCO_E_SYNC_RUNTIME_START           = 94,  /* unable to start sync runtime */
            MCO_E_ALIGN_ERROR                  = 95,  /* bit range get/set align error */
            MCO_E_PINNED_VERSION_LIMIT         = 96,  /* pinned version number limit is reached */
            MCO_E_VERSION_NOT_PINNED           = 97,  /* version is not pinned */
            MCO_E_CURSOR_CLOSED                = 98,  /* cursor is closed */
            MCO_E_CONVERSION                   = 99,  /* Conversion error in binary schema evolution */

            MCO_E_DISK                         = 100, /* general disk error */
            MCO_E_DISK_OPEN                    = 101, /* unable to open persistent storage device */
            MCO_E_DISK_ALREADY_OPENED          = 102, /* persistent storage device already opened */
            MCO_E_DISK_NOT_OPENED              = 103, /* persistent storage device not opened */
            MCO_E_DISK_INVALID_PARAM           = 104, /* invalid disk parameters value */
            MCO_E_DISK_PAGE_ACCESS             = 105, /* attempt to access invalid disk page */
            MCO_E_DISK_OPERATION_NOT_ALLOWED   = 106, /* specified disk operation is not allowed */
            MCO_E_DISK_ALREADY_CONNECTED       = 107, /* persistent storage device is already connected */
            MCO_E_DISK_KEY_TOO_LONG            = 108, /* index key is too long */
            MCO_E_DISK_TOO_MANY_INDICES        = 109, /* too many indexes in persistent classes */
            MCO_E_DISK_TOO_MANY_CLASSES        = 110, /* too many persistent classes */
            MCO_E_DISK_SPACE_EXHAUSTED         = 111, /* persistent storage device is out of space */
            MCO_E_DISK_INCOMPATIBLE_LOG_TYPE   = 112, /* incompatible database log type */
            MCO_E_DISK_BAD_PAGE_SIZE           = 113, /* database page size is not acceptable */
            MCO_E_DISK_SYNC                    = 114, /* failed operation on sync primitive */
            MCO_E_DISK_PAGE_POOL_EXHAUSTED     = 115, /* too many pinned disk pages */
            MCO_E_DISK_CLOSE                   = 116, /* error closing persistent storage device */
            MCO_E_DISK_TRUNCATE                = 117, /* unable to truncate persistent storage device */
            MCO_E_DISK_SEEK                    = 118, /* unable to perform seek in persistent storage device */
            MCO_E_DISK_WRITE                   = 119, /* unable to write to persistent storage device */
            MCO_E_DISK_READ                    = 120, /* unable to read from persistent storage device */
            MCO_E_DISK_FLUSH                   = 121, /* unable to flush to persistent storage device */
            MCO_E_DISK_TOO_HIGH_TREE           = 122, /* index too big */
            MCO_E_DISK_VERSION_MISMATCH        = 123, /* version mismatch */
            MCO_E_DISK_CONFLICT                = 124,  /* MVCC conflict */
            MCO_E_DISK_SCHEMA_CHANGED          = 125,  /* database schema was changed */
            MCO_E_DISK_CRC_MISMATCH            = 126,  /* CRC is not matched for the loaded page */
            
            MCO_E_XML                          = 200,
            MCO_E_XML_INVINT                   = 201, /* invalid integer */
            MCO_E_XML_INVFLT                   = 202, /* invalid float */
            MCO_E_XML_INTOVF                   = 203, /* integer overflow */
            MCO_E_XML_INVBASE                  = 204, /* invalid base for quad (10) */
            MCO_E_XML_BUFSMALL                 = 205, /* buffer too small for double in fixed point format */
            MCO_E_XML_VECTUNSUP                = 206, /* unsupported base type for vector */
            MCO_E_XML_INVPOLICY                = 207, /* invalid xml policy value */
            MCO_E_XML_INVCLASS                 = 208, /* object class different from xml class */
            MCO_E_XML_NO_OID                   = 209, /* first field in the xml object MUST be an OID */
            MCO_E_XML_INVOID                   = 210, /* invalid data in OID field (hex code) */
            MCO_E_XML_INVFLDNAME               = 211, /* invalid field name */
            MCO_E_XML_FLDNOTFOUND              = 212, /* specified field was not found */
            MCO_E_XML_INVENDTAG                = 213, /* invalid closing tag name */
            MCO_E_XML_UPDID                    = 214, /* cannot update OID or AUTOID */
            MCO_E_XML_INVASCII                 = 215, /* invalid xml coding in ascii string */
            MCO_E_XML_INCOMPL                  = 216, /* xml definition incomplete - closing tag not found */
            MCO_E_XML_ARRSMALL                 = 217, /* array is not large enough to hold all elements */
            MCO_E_XML_INVARREL                 = 218, /* invalid name of array element */ 
            MCO_E_XML_EXTRAXML                 = 219, /* extra xml found after parsing */
            MCO_E_XML_NOTWF                    = 220, /* xml not well-formed */
            MCO_E_XML_UNICODE                  = 221, /* bad unicode conversion */
            MCO_E_XML_NOINDEX                  = 222, /* some classes have no indexes, so database cannot be exported */

            MCO_E_NW                           = 300,
            MCO_E_NW_FATAL                     = 301, /* fatal error */
            MCO_E_NW_NOTSUPP                   = 302, /* network is not supported */
            MCO_E_NW_CLOSE_CHANNEL             = 303, /* error closing network channel **/
            MCO_E_NW_BUSY                      = 304, /* network busy (blocked by another listener?) */
            MCO_E_NW_ACCEPT                    = 305, /* accept failed */
            MCO_E_NW_TIMEOUT                   = 306, /* timeout value exceeded */
            MCO_E_NW_INVADDR                   = 307, /* invalid address specified */
            MCO_E_NW_NOMEM                     = 308, /* host name is too long */
            MCO_E_NW_CONNECT                   = 309, /* connect failed */
            MCO_E_NW_SENDERR                   = 310, /* send failed */
            MCO_E_NW_RECVERR                   = 311, /* receive failed */
            MCO_E_NW_CLOSED                    = 312, /* connection was closed (by the remote host) */  
            MCO_E_NW_HANDSHAKE                 = 313, /* handshake failed **/
            MCO_E_NW_CLOSE_SOCKET              = 314, /* error closing socket */
            MCO_E_NW_CREATEPIPE                = 315, /* error creating pipe */
            MCO_E_NW_SOCKET                    = 316, /* socket error */
            MCO_E_NW_SOCKOPT                   = 317, /* setsockopt() error */
            MCO_E_NW_BIND                      = 318, /* bind error */
            MCO_E_NW_SOCKIOCTL                 = 319, /* ioctlsocket() error */
            MCO_E_NW_MAGIC                     = 320, /* invalid magic value */
            MCO_E_NW_INVMSGPARAM               = 321, /* invalid parameter for a message */
            MCO_E_NW_WRONGSEQ                  = 322, /* wrong sequence number for a message */
            MCO_E_NWMCAST_CLOSE_SOCKET         = 323, /* unable to close multicast socket*/
            MCO_E_NWMCAST_SOCKET               = 324, /* multicast socket error */
            MCO_E_NWMCAST_SOCKOPT              = 325, /* unable to set multicast socket option */
            MCO_E_NWMCAST_RECV                 = 326, /* unable to receive data from multicast socket */
            MCO_E_NWMCAST_BIND                 = 327, /* unable to bind multicast socket */
            MCO_E_NWMCAST_NBIO                 = 328, /* unable to ioctl multicast socket */
            MCO_E_NW_KILLED_BY_REPLICA         = 329, /* the master connection was killed by replica */
            MCO_E_NW_WOULDBLOCK                = 330, /* send/recv operation would block */
            MCO_E_NW_SELECT                    = 331, /* send/recv operation would block */
            
            MCO_E_HA                           = 400, /* HA base error code */
            MCO_E_HA_PROTOCOLERR               = 401, /* error in protocol */
            MCO_E_HA_TIMEOUT                   = 402, /* timeout */
            MCO_E_HA_IOERROR                   = 403, /* input/output error */
            MCO_E_HA_MAXREPLICAS               = 404, /* too many replicas requested */
            MCO_E_HA_INIT                      = 405, /* unable to initialize HA */
            MCO_E_HA_RECEIVE                   = 406, /* error receiving HA message **/
            MCO_E_HA_NO_AUTO_OID               = 407, /* no auto_oid index declared in the database schema */
            MCO_E_HA_NOT_INITIALIZED           = 408, /* HA was not initialized */
            MCO_E_HA_INVALID_MESSAGE           = 409, /* invalid HA message Id */
            MCO_E_HA_INVALID_PARAMETER         = 410, /* invalid parameter */
            MCO_E_HA_INVCHANNEL                = 411, /* invalid channel handler */
            MCO_E_HA_INCOMPATIBLE_MODES        = 412, /* incompatible HA mode */
            MCO_E_HA_CLOSE_TEMP                = 413, /* close temporary multicast channel */
            MCO_E_HA_MULTICAST_NOT_SUPP        = 414, /* multicast is not configured */
            MCO_E_HA_HOTSYNCH_NOT_SUPP         = 415, /* hot synchronization is not configured */ 
            MCO_E_HA_ASYNCH_NOT_SUPP           = 416, /* asynchronous replication is not configured */ 
            MCO_E_HA_NO_MEM                    = 417, /* not enough memory to create communication layer descriptors */ 
            MCO_E_HA_BAD_DESCRIPTOR            = 418, /* ha_t structure is not cleared before creation of base channel */  
            MCO_E_HA_CANCEL                    = 419, /* connection was canceled */  
            MCO_E_HA_WRONG_DB_MAGIC            = 420, /* wrong DB magic value */
            MCO_E_HA_COMMIT                    = 421, /* master commit error, break commit loop */
            MCO_E_HA_MANYREPLICAS              = 422, /* attempt to attach too many replicas */
            MCO_E_NOT_MASTER                   = 423, /* master-mode was not set */
            MCO_E_HA_STOPPED                   = 424, /* replication was stopped */
            MCO_E_HA_NOWRITETXN                = 425, /* read-write transactions are prohibited on replica */
            MCO_E_HA_PM_BUFFER                 = 426, /* page memory buffer error */
            MCO_E_HA_NOT_REPLICA               = 427, /* not Currently in replica-mode */
            MCO_E_HA_BAD_DICT                  = 428, /* master's db dictionary is incompatible with replica's */
            MCO_E_HA_BINEV_NOT_SUPP            = 429, /* binary schema evolution is not configured */
            
            MCO_E_UDA                          = 500, /* UDA base error code */
            MCO_E_UDA_TOOMANY_ENTRIES          = 501, /* allocated entry num exceeded */
            MCO_E_UDA_NAME_TOO_LONG            = 502, /* long entry name */
            MCO_E_UDA_DUPLICATE                = 503, /* duplicate entry name */
            MCO_E_UDA_DICT_NOTFOUND            = 504, /* dictionary (entry) not found by dict_no, name or connection */
            MCO_E_UDA_STRUCT_NOTFOUND          = 505, /* structure not found by struct_no or name */
            MCO_E_UDA_FIELD_NOTFOUND           = 506, /* field not found by field_no or name */
            MCO_E_UDA_INDEX_NOTFOUND           = 507, /* index not found by index_no or name */
            MCO_E_UDA_IFIELD_NOTFOUND          = 508, /* indexed field not found by ifield_no or name */
            MCO_E_UDA_COLLATION_NOTFOUND       = 509, /* collation not found (by collation_no or by name) */
            MCO_E_UDA_STRUCT_NOT_CLASS         = 510, /* structure is not a class, so some operations are not allowed */
            MCO_E_UDA_WRONG_KEY_NUM            = 511, /* key number in lookup() and compare() differs from index spec */
            MCO_E_UDA_WRONG_KEY_TYPE           = 512, /* key types in lookup() and compare() differs from index spec */
            MCO_E_UDA_WRONG_OPCODE             = 513, /* invalid OPCODE (e.g. not MCO_EQ for hash index) */
            MCO_E_UDA_SCALAR                   = 514, /* attempt to get mco_uda_length() on scalar field */
            MCO_E_UDA_NOT_DYNAMIC              = 515, /* attempt to call mco_uda_field_alloc/free() for non-vector or optional struct field */
            MCO_E_UDA_WRONG_VALUE_TYPE         = 516, /* type of value and field are different in mco_uda_put() */
            MCO_E_UDA_READONLY                 = 517, /* Attempt to call mco_uda_put() for read-only fields: oid, autoid, autooid */
            MCO_E_UDA_WRONG_CLASS_CODE         = 518, /* invalid class code */
            MCO_E_UDA_DICT_NOT_DIRECT          = 519, /* in mco_uda_db_open(), entry holds database pointer, not dictionary */
            MCO_E_UDA_INDEX_NOT_USERDEF        = 520, /* Attempt to call mco_uda_register_udf() for non-userdef index */
            MCO_E_UDA_EVENT_NOTFOUND           = 521, /* event not found (by event_no) */

            MCO_E_TL                           = 600, /* TL base error code */
            MCO_E_TL_INVAL                     = 601, /* invalid argument value */
            MCO_E_TL_ALREADY_STARTED           = 602, /* TL already started */
            MCO_E_TL_NOT_STARTED               = 603, /* TL is not started */
            MCO_E_TL_LOG_NOT_OPENED            = 604, /* LOG file is not opened */
            MCO_E_TL_INVFORMAT                 = 605, /* completely corrupted LOG file */
            MCO_E_TL_INVDATA                   = 606, /* broken record during recovering */
            MCO_E_TL_IO_ERROR                  = 607, /* input/output error */
            MCO_E_TL_NOT_ITERABLE              = 608, /* LOG file created without flag MCO_TRANSLOG_ITERABLE or unsupported transaction manager is applied */
            MCO_E_TL_TRANS_STARTED             = 609, /* function invoked inside transaction */
            MCO_E_TL_PIPE_USED                 = 610, /* pipe still opened by previous instance of reader */
            MCO_E_TL_PIPE_LOST                 = 611, /* pipe were closed in all of writers connections. Keep at least one opened between log start and stop */
            MCO_E_TL_PIPE_TERM                 = 612, /* reader abnormally terminated its job */
            MCO_E_TL_NO_AUTO_OID               = 613, /* no auto_oid index declared in the database schema */

            MCO_E_NO_DIRECT_ACCESS             = 700, /* direct access to the structure is not possible */

            MCO_E_DDL_NOMEM                    = 800, /* dictionary can not fir in the reseerved area */
            MCO_E_DDL_UNDEFINED_STRUCT         = 801, /* struct referenced by field is not yet defined */
            MCO_E_DDL_INVALID_TYPE             = 802, /* unsupported field type */
            MCO_E_DDL_FIELD_NOT_FOUND          = 803, /* reference field is not found in the class */
            MCO_E_DDL_INTERNAL_ERROR           = 804, /* internal error */

            MCO_E_CLUSTER                      = 900, /* cluster base error code */
            MCO_E_CLUSTER_NOT_INITIALIZED      = 901, /* non-cluster database */
            MCO_E_CLUSTER_INVALID_PARAMETER    = 902, /* invalid cluster parameters value */
            MCO_E_CLUSTER_STOPPED              = 903, /* replication was stopped */        
            MCO_E_CLUSTER_PROTOCOLERR          = 904, /* replication protocol error */
            MCO_E_CLUSTER_NOQUORUM             = 905, /* no node's quorum */
            MCO_E_CLUSTER_BUSY                 = 906, /* can't stop cluster with active transactions */
            MCO_E_CLUSTER_INCOMPATIBLE_MODE    = 907, /* incompatible modes on different nodes */
            MCO_E_CLUSTER_SYNC                 = 908, /* error during synchronization */
            MCO_E_CLUSTER_INCOMPATIBLE_ARCH    = 909, /* incompatible architecture of different nodes */
            MCO_E_EVAL                         = 999, /* evaluation version limitation */
        
            /* unrecoverable (fatal) error code bases */
            MCO_ERR_DB                         = 100000,   /* database */
            MCO_ERR_DICT                       = 110000,   /* dictionary */
            MCO_ERR_CURSOR                     = 120000,   /* cursor */
            MCO_ERR_PMBUF                      = 130000,   /* pm buffer */
            MCO_ERR_COMMON                     = 140000,   /* common routines */
            MCO_ERR_HEAP                       = 150000,   /* heap manager */
            MCO_ERR_OBJ                        = 160000,   /* object allocator */
            MCO_ERR_BLOB                       = 170000,   /* blob operation */
            MCO_ERR_FREC                       = 180000,   /* record allocator */
            MCO_ERR_VOLUNTARY                  = 190000,   /* voluntary index */
            MCO_ERR_LOADSAVE                   = 200000,   /* db save and load */
            MCO_ERR_PGMEM                      = 210000,   /* page memory */
            MCO_ERR_EV_SYN                     = 220000,   /* syncronous events */
            MCO_ERR_EV_ASYN                    = 230000,   /* async events */
            MCO_ERR_EV_W                       = 240000,   /* event wrappers */
            MCO_ERR_XML_W                      = 250000,   /* XML serialization */
            MCO_ERR_XML_SC                     = 260000,   /* XML schema */
            MCO_ERR_BTREE                      = 270000,   /* btree */
            MCO_ERR_HASH                       = 280000,   /* hash */
            MCO_ERR_RECOV                      = 290000,   /* recovery */
            MCO_ERR_FCOPY                      = 300000,   /* copy fields */
            MCO_ERR_INST                       = 330000,   /* db instance */
            MCO_ERR_TRN                        = 340000,   /* transaction */
            MCO_ERR_TMGR                       = 370000,   /* transaction manager */
            MCO_ERR_SYNC                       = 400000,   /* general sync */
            MCO_ERR_ORDER                      = 450000,   /* ordering and hash index */
            MCO_ERR_SEM                        = 460000,   /* semaphores */
            MCO_ERR_SHM                        = 470000,   /* shared memory */
            MCO_ERR_SER                        = 500000,   /* serialization */
            MCO_ERR_HA                         = 510000,   /* high availability */
            MCO_ERR_DB_NOMEM                   = 520000,   /* insufficient memory */
            MCO_ERR_OBJECT_HANDLE              = 530000,   /* invalid object handle */
            MCO_ERR_UNSUPPORTED_FLOAT          = 540000,   /* support of float type is disabled */
            MCO_ERR_UNSUPPORTED_DOUBLE         = 550000,   /* deprecated */ 
            
            MCO_ERR_DB_NOMEM_HASH              = 560000,   /* insufficient memory in hash index */
            MCO_ERR_DB_NOMEM_HEAP              = 570000,   /* insufficient memory in heap manager */
            MCO_ERR_DB_NOMEM_TRANS             = 580000,   /* insufficient memory in transaction manager */
            MCO_ERR_DB_NAMELONG                = 590000,   /* database name is too long */
            MCO_ERR_DB_VERS_MISMATCH           = 600000,   /* version of eXtremeDB runtime mismatch */
            MCO_ERR_RUNTIME                    = 610000,   /* invalid type of runtime library */
            MCO_ERR_INMEM_ONLY_RUNTIME         = 620000,   /* persistent class in the schema but inmem-only runtime */
            
            MCO_ERR_DISK                       = 700000,   /* general disk error */
            MCO_ERR_DISK_WRITE                 = 710000,   /* unable to write to persistent storage */
            MCO_ERR_DISK_READ                  = 720000,   /* unable to read from persistent storage */
            MCO_ERR_DISK_FLUSH                 = 730000,   /* unable to flush to persistent storage */
            MCO_ERR_DISK_CLOSE                 = 740000,   /* error closing persistent storage device */
            MCO_ERR_DISK_TRUNCATE              = 750000,   /* unable to truncate persistent storage device */
            MCO_ERR_DISK_SEEK                  = 760000,   /* unable to seek in persistent storage device */
            MCO_ERR_DISK_OPEN                  = 770000,   /* unable to open persistent storage device */
            MCO_ERR_DISK_ALREADY_OPENED        = 780000,   /* persistent storage device already opened */
            MCO_ERR_DISK_NOT_OPENED            = 790000,   /* persistent storage device was not opened */
            MCO_ERR_DISK_INVALID_PARAM         = 800000,   /* invalid parameter value */
            MCO_ERR_DISK_PAGE_ACCESS           = 810000,   /* page access fatal error */
            MCO_ERR_DISK_INTERNAL_ERROR        = 820000,   /* internal fatal error */
            MCO_ERR_DISK_OPERATION_NOT_ALLOWED = 830000,   /* operation not allowed fatal error */
            MCO_ERR_DISK_ALREADY_CONNECTED     = 840000,   /* persistent storage device already connected */
            MCO_ERR_DISK_TOO_MANY_INDICES      = 850000,   /* too many indexes in persistent classes */
            MCO_ERR_DISK_TOO_MANY_CLASSES      = 860000,   /* too many persistent classes */
            MCO_ERR_DISK_SPACE_EXHAUSTED       = 870000,   /* persistent storage device out of space */
            MCO_ERR_DISK_PAGE_POOL_EXHAUSTED   = 880000,   /* too many pinned disk pages */
            MCO_ERR_DISK_INCOMPATIBLE_LOG_TYPE = 890000,   /* incompatible database log type */
            MCO_ERR_DISK_BAD_PAGE_SIZE         = 900000,   /* page size is not acceptable */
            MCO_ERR_DISK_SYNC                  = 910000,   /* failed operation on sync. primitive */
            MCO_ERR_DISK_CRC                   = 920000,   /* wrong CRC code of disk page */
            MCO_ERR_CHECKPIN                   = 930000,   /* unbalanced pin/unpin */
            MCO_ERR_CONN                       = 940000,   /* connection processing */
            MCO_ERR_REGISTRY                   = 950000,   /* registry processing */
            MCO_ERR_INDEX                      = 960000,   /* index processing */
            MCO_ERR_VTMEM                      = 970000,   /* in-mememory only runtime */
            MCO_ERR_VTDSK                      = 980000,   /* mixed runtime */
            MCO_ERR_RTREE                      = 990000,   /* rtree index */
            MCO_ERR_UDA                        = 1000000,  /* Uniform Data Access */
            MCO_ERR_PTREE                      = 1010000,  /* patricia tree index */
            MCO_ERR_TL                         = 1020000,  /* transaction log */
            MCO_ERR_CLUSTER                    = 1030000,  /* cluster */
            MCO_ERR_CLNWTCP                    = 1040000,  /* cluster TCP transport */

            MCO_ERR_LAST                       = 1999999   /* the latest one */

        } MCO_RET; /* return code */

        #define mco_min_page_size    ( 16*sizeof(mco_offs_t))   /* min size of a page    */
        #define mco_cursor_size      (100*sizeof(mco_offs_t))   /* cursor structure size */
        #define mco_handle_size      ( 14*sizeof(mco_offs_t))   /* object handle size    */

        /* boolean type */
        typedef int mco_bool;
        #define MCO_YES 1
        #define MCO_NO  0

        #define mco_trans_size       20   /* max number of updated or deleted objects in one transaction */
        #define mco_handle_size_w    ( mco_handle_size / sizeof(MCO_PUB_STRUCT_BASE) )   /* defined in mcoquad.h */
        #define mco_cursor_size_w    ( mco_cursor_size / sizeof(MCO_PUB_STRUCT_BASE) )

        typedef MCO_PUB_STRUCT_BASE MCO_Hf[mco_handle_size_w];
        MCO_RET mco_get_class_code ( void * object_handle, uint2 * class_code);

        typedef struct mco_cursor_t_
        {
            MCO_PUB_STRUCT_BASE c[mco_cursor_size_w];
        } mco_cursor_t,  /* cursor (structure)            */
        *mco_cursor_h; /* cursor handle (pointer)       */

        #ifdef MCO_NO_FORWARDS

            typedef void* mco_trans_h;
            typedef void* mco_db_h;
            typedef void* mco_dictionary_h;
            typedef void* mco_calculator_h;
            typedef void* mco_collate_h;

        #else 

            struct mco_trans_t_;
            typedef struct mco_trans_t_* mco_trans_h; /* transaction handle (pointer)  */

            struct mco_db_t_;
            typedef struct mco_db_t_* mco_db_h; /* database handle (pointer)     */

            struct mco_dictionary_t_;
            typedef struct mco_dictionary_t_* mco_dictionary_h; /* dictionary handle (pointer)   */

            struct mco_calculator_t_;
            typedef struct mco_calculator_t_* mco_calculator_h; /* calculator handle (pointer) */

            struct mco_collate_t_;
            typedef struct mco_collate_t_* mco_collate_h; /* custom collation handle (pointer) */
        #endif 

        /* transaction priority values */

        typedef enum MCO_TRANS_PRIORITY_E_
        {
            MCO_TRANS_IDLE       = -2, 
            MCO_TRANS_BACKGROUND = -1, 
            MCO_TRANS_FOREGROUND = 0, 
            MCO_TRANS_HIGH       = 1, 
            MCO_TRANS_ISR        = 2
        } MCO_TRANS_PRIORITY;

        typedef enum MCO_TRANS_ISOLATION_LEVEL_E_
        { 
            MCO_DEFAULT_ISOLATION_LEVEL = 0x0,
            MCO_READ_COMMITTED          = 0x1,
            MCO_REPEATABLE_READ         = 0x2,
            MCO_SERIALIZABLE            = 0x4      
        } MCO_TRANS_ISOLATION_LEVEL;  

        /* transaction type values */
        typedef enum MCO_TRANS_TYPE_E_
        {
            MCO_READ_ONLY = 0, MCO_UPDATE = 1, MCO_READ_WRITE = 2, MCO_EXCLUSIVE = 3
        } MCO_TRANS_TYPE;

        /* Device management */
        #define MCO_MEMORY_NULL                  0  /* an invalid device */
        #define MCO_MEMORY_CONV                  1  /* a conventional memory region (non-shared memory) */
        #define MCO_MEMORY_NAMED                 2  /* a named memory region (shared memory) */
        #define MCO_MEMORY_FILE                  3  /* a file device */
        #define MCO_MEMORY_MULTIFILE             4  /* a multifile device */
        #define MCO_MEMORY_RAID                  5   /* a RAID device */
        #define MCO_MEMORY_INT_DESC              6   /* an integer descripted region (shard memory) */
        #define MCO_MEMORY_CYCLIC_FILE_BUF       7   /* pair of files to organize cyclic buffer */
        
        #define MCO_MEMORY_ASSIGN_DATABASE       0   /* a memory region for meta- and user-data, indeces and other database structures */
        #define MCO_MEMORY_ASSIGN_CACHE          1   /* a memory region for disk caching purposes */
        #define MCO_MEMORY_ASSIGN_PERSISTENT     2   /* a persistent storage device (file, multi-file) */
        #define MCO_MEMORY_ASSIGN_LOG            3   /* a log device (file, multi-file) */
        #define MCO_MEMORY_ASSIGN_HA_ASYNC_BUF   4   /* an async buffer device for HA */
        #define MCO_MEMORY_ASSIGN_PIPE_BUF       5   /* buffer for TL pipe */

        #define MCO_MAX_MEMORY_NAME      64
        #define MCO_MAX_FILE_NAME       256
        #define MCO_MAX_MULTIFILE_NAME   64

        typedef struct mco_device_t_ {
            unsigned int type;       /* none, conv, named, file, raid, etc */
            unsigned int assignment; /* none, db-segment, cache-segment, db-file, log-file */
            mco_size_t   size;
            union {
                struct {
                    void * ptr;
                } conv;
                struct {
                    char name[MCO_MAX_MEMORY_NAME];
                    unsigned int flags;
                    void * hint;
                } named;
                struct {
                    int flags;
                    char name[MCO_MAX_FILE_NAME];
                } file;
                struct {
                    int flags;
                    char name[MCO_MAX_MULTIFILE_NAME];
                    mco_offs_t segment_size;
                } multifile;
                struct {
                    int flags;
                    char name[MCO_MAX_MULTIFILE_NAME];
                    int level;
                } raid;
                struct {
                    unsigned long handle;
                } idesc;
            } dev;
        } mco_device_t, *mco_device_h;

        /* Database management */

        MCO_RET mco_runtime_start(void);
        MCO_RET mco_runtime_stop(void);
        unsigned int mco_current_registry_size(void);
        MCO_RET mco_close_all_instances(void); /* for multiprocessing only */
        MCO_RET mco_db_databases(char* lpBuffer, mco_size32_t buffer_size, mco_counter32_t skip_first);

        /* #ifdef MCO_CFG_USERDEF_IDX */
        typedef int2  (*mco_compare_userdef_f)           ( MCO_Hf * obj1, MCO_Hf * obj2);
        typedef int2  (*mco_compare_extkey_userdef_f)    ( MCO_Hf * obj1, void * key);
        /* Vector-based version:  */
        typedef int2  (*mco_compare_userdef_vb_f)        ( MCO_Hf * obj1, int index1, MCO_Hf * obj2, int index2);
        typedef int2  (*mco_compare_extkey_userdef_vb_f) ( MCO_Hf * obj1, int index1, void * key);

        typedef uint4 (*mco_hash_userdef_f)              ( MCO_Hf * obj);
        typedef uint4 (*mco_hash_extkey_userdef_f)       ( void * key);
        /* Vector-based version:  */
        typedef uint4 (*mco_hash_userdef_vb_f)           ( MCO_Hf * obj, int index);
        /* Special version (for UDA) */
        typedef uint4 (*mco_hash_extkey_userdef_spec_f)  ( void * key, mco_db_h db, uint2 index_num);
 
        #define MCO_UDF_SPECIAL_EXTHASH   0x1

        struct mco_userdef_funcs_t_ {
            union {
                mco_compare_userdef_f            nvb;
                mco_compare_userdef_vb_f         vb;
            } fcomp;
            union {
                mco_compare_extkey_userdef_f     nvb;
                mco_compare_extkey_userdef_vb_f  vb;
            } fcomp_ext;
            union {
                mco_hash_userdef_f               nvb;
                mco_hash_userdef_vb_f            vb;
            } fhash;
            union {
                mco_hash_extkey_userdef_f        u;  
                mco_hash_extkey_userdef_spec_f   spec;       
            } fhash_ext;
            union {
                uint4 flags;
                void  *user_context;
            } p;
        };
        typedef  struct mco_userdef_funcs_t_  mco_userdef_funcs_t;
        typedef  struct mco_userdef_funcs_t_ *mco_userdef_funcs_h;

        MCO_RET     mco_db_register_udf ( const char * db_name, mco_userdef_funcs_h udfs);
        /* #endif MCO_CFG_USERDEF_IDX */

        typedef int2 (*mco_compare_collation_f) ( mco_collate_h c1, uint2 len1, mco_collate_h c2, uint2 len2);
        typedef uint4 (*mco_hash_collation_f) ( mco_collate_h c, uint2 len);
        typedef struct mco_collation_funcs_t_ {
            mco_compare_collation_f comp;
            mco_hash_collation_f    hash;
        } mco_collation_funcs_t, *mco_collation_funcs_h;

        MCO_RET     mco_db_register_collations ( const char * db_name, mco_collation_funcs_h colls);
        
        typedef enum MCO_COMMIT_POLICY_E
        {
           MCO_COMMIT_SYNC_FLUSH, /* default  */
           MCO_COMMIT_BUFFERED,   /* runtime buffered transactions */
           MCO_COMMIT_DELAYED,    /* runtime buffered transactions, with commit criteria */
           MCO_COMMIT_NO_SYNC     /* changes are not synchronously written to the disk */
        } MCO_COMMIT_POLICY;

        #define MCO_PARAM_NOT_SPECIFIED 0
        typedef struct mco_log_params_t_
        {
            MCO_COMMIT_POLICY default_commit_policy;
            mco_offs_t        redo_log_limit;
            mco_offs_t        delayed_commit_threshold;
            mco_counter32_t   max_delayed_transactions;
            uint4             max_commit_delay; /* in milliseconds */
        } mco_log_params_t;

        typedef enum MCO_LOG_TYPE_ {
            NO_LOG, REDO_LOG, UNDO_LOG
        } MCO_LOG_TYPE;

        typedef enum MCO_DB_MODE_MASK_ { 
            MCO_DB_MODE_MVCC_AUTO_VACUUM      = 0x01,
            MCO_DB_MODE_SMART_INDEX_INSERT    = 0x02,
            MCO_DB_OPEN_EXISTING              = 0x04,
            MCO_DB_USE_CRC_CHECK              = 0x08,
            MCO_DB_TRANSIENT                  = 0x10,
            MCO_DB_LAZY_MEM_INITIALIZATION    = 0x20,
            MCO_DB_MURSIW_DISK_COMMIT_OPTIMIZATION = 0x40
        } MCO_DB_MODE_MASK;

        #define MCO_INFINITE_DATABASE_SIZE 0

        typedef struct mco_db_params_t_ {
            uint2            mark;                    /**/
            uint2            mem_page_size;           /* memory page size */
            uint2            disk_page_size;          /* disk page size, typical 4096 bytes, set to zero for in-memory only database */
            uint2            db_max_connections;      /* max number of connections */
            mco_offs_t       disk_max_database_size;  /* max size of persistent database */
            mco_offs_t       file_extension_quantum;  /* quantum of increasing size of database file (can help to reduce file fragmentation) */
            MCO_LOG_TYPE     db_log_type;             /* database logging method */
            uint2            connection_context_size; /* recovery connection context */
            
            uint2            hash_load_factor;        /* criteria of hash reallocation in percent of used items */
            uint2            index_optimistic_lock_threshold; /* maximum number of active write transactions when
                                                                 optimistic locking of B-Tree indexes can be performed */
            mco_log_params_t log_params;              /* initial log settings */
            
            int              mode_mask;               /* open mode mask */
            int              min_conn_local_pages;    /* minimal number of pages in per-connection allocator */
            int              max_conn_local_pages;    /* maximal number of pages in per-connection allocator */

            int              allocation_bitmap_caching_priority; /* priority of allocator bitmap pages in LRU page pool */
            int              index_caching_priority; /* priority of indices pages in LRU page pool */
            int              object_caching_priority;/* priority of objects (non-blob) pages in LRU page pool */

            struct mco_ddl_dictionary_t_* ddl_dict;
            mco_size_t       ddl_dict_size;
            int              ddl_dict_build_flags;

            char*            cipher_key; /* database encryption key */
            mco_bool         dynamic_hash; /* dynamically extend hash table when number of items exceeds load factor */
        } mco_db_params_t;
        
        /* Set default values. Call this first then customize the params according to your requirements. */
        void    mco_db_params_init( mco_db_params_t * params ); 

        /* The general approach is to call mco_db_open_dev() and mco_db_extend_dev() to open or extend a database 
        on specified memory devices with the specified params */
        MCO_RET mco_db_open_dev   ( const char* db_name, mco_dictionary_h dict, mco_device_t * devs, mco_size_t n_devs, mco_db_params_t * params );
        MCO_RET mco_db_extend_dev ( const char* db_name, mco_device_t * dev );
        
        /* The following are provided to open or extend a database on conventional memory and for backward compatibility. */
        MCO_RET mco_db_open       ( const char* db_name, mco_dictionary_h dict, void* mem_ptr, mco_size_t total_size, uint2 page_size );
        MCO_RET mco_db_extend     ( const char* db_name, void* mem_ptr, mco_size_t size);            
        /* This function provides compatibility with 3.5 version and replaces combination of mco_db_open+mco_disk_open function calls */
        MCO_RET mco_db_open_disk( const char* db_name, mco_dictionary_h dict, void* mem_ptr, mco_size_t mem_size, uint2 mem_page_size, 
                                  const char* db_file_path, const char* log_file_path, void* disk_cache_ptr, mco_size_t disk_cache_size, 
                                  int disk_page_size, mco_offs_t max_database_size, MCO_LOG_TYPE log_type);
        /* close a database */
        MCO_RET mco_db_close      ( const char* db_name );
        /* terminate a database */
        MCO_RET mco_db_kill       ( const char* db_name );

        /* connect to an existing database specifying a database context */
        MCO_RET mco_db_connect_ctx( const char* db_name, void const* context, /*OUT*/ mco_db_h* pdb);
        /* connect to an existing database without a connection context */
        MCO_RET mco_db_connect    ( const char* db_name, /*OUT*/ mco_db_h* pdb);
        /* get the context associated with a connection */
        void*   mco_db_connection_context( mco_db_h db );

        /* close a connection */
        MCO_RET mco_db_disconnect ( mco_db_h db );
        
	      /* remove all objects from a database */
	      MCO_RET mco_db_clean      ( mco_db_h db );

        MCO_RET mco_db_recover(mco_db_h db, mco_db_h recovered_connection);
        MCO_RET mco_db_recover_all(mco_db_h db);

        MCO_RET mco_db_free_pages(mco_db_h db,  /*OUT*/mco_size32_t* retvalue);
        MCO_RET mco_db_total_pages(mco_db_h db,  /*OUT*/mco_size32_t* retvalue);
        MCO_RET mco_db_page_size(mco_db_h db,  /*OUT*/uint2* retvalue);

        /**
         * This enum defines sniffer policy: when sniffer should call the user supplied callback function to check 
         * the status of a connection.
         */
        typedef enum mco_sniffer_policy {
            MCO_SNIFFER_INSPECT_ACTIVE_CONNECTIONS,
            MCO_SNIFFER_INSPECT_ACTIVE_TRANSACTIONS,
            MCO_SNIFFER_INSPECT_HANGED_TRANSACTIONS

        } mco_sniffer_policy;
        /** 
         * This typedef defines the prototype for a user defined callback function that detects dead connections. 
         * This function must return MCO_S_DEAD_CONNECTION to force database recovery, MCO_S_OK if the connection is ok. 
         * From the eXtremeDB runtime's point of view the two parameters "db" and "context" are opaque data. 
         * (NB: "context" is typically supplied by calling function mco_db_connect_ctx() which fills in a data block 
         * of size MCO_CFG_CONNECTION_CONEXT_SIZE).  Parameter "trans_no" is the number of active transaction 
         * (0 if no active transaction).  The function must return MCO_S_DEAD_CONNECTION if the connection associated
         * with "context" is considered dead and should be recovered, MCO_S_OK otherwise. Any other return code will 
         * cause interruption of mco_db_sniffer which will return this error code to the calling process.
         */
        typedef MCO_RET (*mco_sniffer_callback_t)(mco_db_h db, void* context, mco_trans_counter_t trans_no);
        /**
         * Call mco_db_sniffer() to inspect the status of all database connections using the user provided callback 
         * function, and perform database recovery if dead connections were detected. 
         * Parameter "db" is a connection handle, and "callback" is the user defined function implementing logic
         * (using OS, timeout, watchdogs, etc.) to detect dead database connections.  If this callback returns 
         * MCO_S_DEAD_CONNECTION then recovery of the database will be performed according to the sniffer policy
         * specified in parameter "policy" (one of the sniffer policies defined in the mco_sniffer_policy enum). 
         * This policy specifies for which connections sniffer will call the user's callback fuction.
         */
        MCO_RET mco_db_sniffer(mco_db_h db, mco_sniffer_callback_t callback, mco_sniffer_policy policy);

        /* Transaction management */
        MCO_RET mco_trans_start(mco_db_h db, MCO_TRANS_TYPE type, MCO_TRANS_PRIORITY pri,  /*OUT*/mco_trans_h* p_trans);
        MCO_RET mco_trans_start_ex(mco_db_h db, MCO_TRANS_TYPE type, MCO_TRANS_PRIORITY pri, MCO_TRANS_ISOLATION_LEVEL level, /*OUT*/mco_trans_h* p_trans);

        MCO_RET mco_trans_upgrade(mco_trans_h t);
        MCO_RET mco_trans_checkpoint(mco_trans_h t);
        MCO_RET mco_trans_commit(mco_trans_h t);
        MCO_RET mco_trans_rollback(mco_trans_h t);
        MCO_RET mco_trans_type(mco_trans_h t,  /*OUT*/MCO_TRANS_TYPE* type);
        MCO_RET mco_trans_no(mco_trans_h t, mco_trans_counter_t* no);

        int     mco_trans_get_supported_isolation_levels();
        int     mco_trans_set_unused_versions_limit(mco_db_h db, int max_archived_versions);
        int     mco_trans_set_cleanup_period(mco_db_h db, int cleanup_period, mco_bool per_connection_cleanup);
        void    mco_trans_optimistic_threshold(mco_db_h db, int max_conflicts_percent, int disable_period);
        MCO_TRANS_ISOLATION_LEVEL mco_trans_set_default_isolation_level(mco_db_h db, MCO_TRANS_ISOLATION_LEVEL level);

        MCO_RET mco_get_last_error(mco_trans_h t);

        MCO_RET mco_trans_commit_phase1(mco_trans_h t);
        MCO_RET mco_trans_commit_phase2(mco_trans_h t);

        MCO_RET mco_get_last_autoid(mco_db_h con, uint8* autoid);

        typedef enum MCO_TRANS_OBJ_STATE_
        {
            MCO_TRANS_OBJ_CREATED     = 0x01,
            MCO_TRANS_OBJ_DELETED     = 0x02,
            MCO_TRANS_OBJ_ALL_DELETED = 0x04
        } MCO_TRANS_OBJ_STATE;

        typedef MCO_RET (*mco_trans_iterator_callback_t)(mco_trans_h trans, MCO_Hf* obj, int cid, int obj_state, void* user_ctx);

        MCO_RET mco_trans_iterate(mco_trans_h trans, mco_trans_iterator_callback_t callback, void* user_ctx);

        /* Cursor operators */
        typedef enum MCO_OPCODE_E_
        {
            MCO_LT = 1, MCO_LE = 2, MCO_EQ = 3, MCO_GE = 4, MCO_GT = 5,
            MCO_OVERLAP = 6, MCO_CONTAIN = 7, MCO_EX = 8, MCO_BEST = 9, MCO_PREF = 10,MCO_NEXT_MATCH = 11,MCO_NEIGHBOURHOOD = 12
        } MCO_OPCODE;


        /* cursor navigation */
        MCO_RET mco_cursor_check(mco_trans_h t, mco_cursor_h c);
        MCO_RET mco_cursor_first(mco_trans_h t, mco_cursor_h c);
        MCO_RET mco_cursor_last(mco_trans_h t, mco_cursor_h c);
        MCO_RET mco_cursor_next(mco_trans_h t, mco_cursor_h c);
        MCO_RET mco_cursor_prev(mco_trans_h t, mco_cursor_h c);
        MCO_RET mco_cursor_close(mco_trans_h t, mco_cursor_h c);
        MCO_RET mco_cursor_store(mco_trans_h t, mco_cursor_h c);

        /* cursor types */
        typedef enum MCO_CURSOR_TYPE_E_
        {
            MCO_LIST_CURSOR = 0, MCO_TREE_CURSOR = 1, MCO_HASH_CURSOR = 2, MCO_KDTREE_CURSOR = 3, MCO_PTREE_CURSOR = 4,
            MCO_RTREE_CURSOR = 5
        } MCO_CURSOR_TYPE;

        /* get cursor information */
        MCO_RET mco_cursor_type(mco_cursor_h c,  /*OUT*/MCO_CURSOR_TYPE* type);
        MCO_RET mco_cursor_get_class_code(mco_cursor_h c,  /*OUT*/uint2* rescode);

        /* runtime statistics */
        typedef struct mco_class_stat_t_
        {
            mco_counter_t objects_num;
            mco_counter32_t versions_num;
            mco_counter32_t core_pages; /* pages used for all data except blobs */
            mco_counter32_t blob_pages; /* pages used by blobs */
            mco_counter_t core_space; /* in bytes, not counting blobs */
        } mco_class_stat_t, * mco_class_stat_h;

        /* get runtime statistics for a class */
        MCO_RET mco_class_stat_get(mco_trans_h t, uint2 class_code,  /*OUT*/mco_class_stat_h stat);

        /* define index characteristics */
        #define MCO_IDXST_TYPE_MEM         0      /* In-memory index */
        #define MCO_IDXST_TYPE_DISK        1      /* Persistent index */
        #define MCO_IDXST_TYPE_MASK        1      
        
        #define MCO_IDXST_NATURE_BTREE     0      /* binary tree index */
        #define MCO_IDXST_NATURE_PTREE     2      /* Patricia tree index*/
        #define MCO_IDXST_NATURE_KDTREE    4      /* KD-tree index */
        #define MCO_IDXST_NATURE_HASH      6      /* hash index */
        #define MCO_IDXST_NATURE_META      8      /* meta-index */
        #define MCO_IDXST_NATURE_RTREE     10     /* R-tree index */
        #define MCO_IDXST_NATURE_MASK      14
        
        #define MCO_IDXST_FEATURE_UNIQUE   0x10   /* Unique index */
        #define MCO_IDXST_FEATURE_UDF      0x20   /* User-defined index */

        #define MCO_IDXST_FUNCTION_REGULAR 0      /* Regular class index */
        #define MCO_IDXST_FUNCTION_OID     0x040   /* Object-ID meta-index */
        #define MCO_IDXST_FUNCTION_AUTOOID 0x080   /* Auto object-ID meta-index */
        #define MCO_IDXST_FUNCTION_AUTOID  0x0C0   /* Auto object id meta-index*/
        #define MCO_IDXST_FUNCTION_LIST    0x100   /* List meta-index */
        #define MCO_IDXST_FUNCTION_MASK    0x1C0
        
        typedef struct mco_index_stat_tree_t_ {
            mco_counter_t levels_num;             /* tree height */
            mco_counter_t duplicates_num;         /* number of duplicates, not implemented yet */
        } mco_index_stat_tree_t;
        
        typedef struct mco_index_stat_kdtree_t_ {
            mco_counter_t levels_num;             /* tree height */
        } mco_index_stat_kdtree_t;
        
        typedef struct mco_index_stat_hash_t_ {
            mco_counter_t avg_chain_length;       /* average number of keys in a basket */
            mco_counter_t max_chain_length;       /* maximum number of keys in a basket */
        } mco_index_stat_hash_t;
        
        typedef struct mco_index_stat_rtree_t_ {
            mco_counter_t levels_num;             /* tree height */
            mco_counter_t duplicates_num;         /* number of duplicates, not implemented yet */
        } mco_index_stat_rtree_t;
        
        typedef struct mco_index_stat_meta_t_ {
            mco_counter_t disk_pages_num;         /* number of disk pages */
        } mco_index_stat_meta_t;
        
        typedef struct mco_index_stat_t_ {
            uint2         class_code;             /* class code that the index belongs */
            uint4         type;                   /* type, MCO_IDXST_ flags */
            char        * plabel;                 /* label of the index */
            mco_counter_t keys_num;               /* number of keys in the index */
            mco_counter_t pages_num;              /* number of pages used by the index */
            union {
                mco_index_stat_tree_t   btree;     /* specific btree stats */
                mco_index_stat_kdtree_t kdtree;    /* specific kdtree stats */
                mco_index_stat_hash_t   hash;      /* specific hash stats */
                mco_index_stat_tree_t   ptree;     /* specific patricia tree stats */
                mco_index_stat_rtree_t  rtree;     /* specific r-tree stats */
                mco_index_stat_meta_t   meta;      /* specific meta-index stats */
            } spec;
        } mco_index_stat_t, * mco_index_stat_h;
        
        /* get the number of indexes in the database */
        MCO_RET mco_index_stat_num( mco_trans_h t, uint2 * pnidx); 
        /* get statistics for an index */
        MCO_RET mco_index_stat_get( mco_trans_h t, uint2   index, mco_index_stat_t * stat );

        /* unrecoverable error handler */
        typedef void(*mco_error_handler_f)(MCO_RET errcode);
        void mco_error_set_handler(mco_error_handler_f f);

        /**
         * Depending on the configuration, extended information (file, line) may be available. 
         * If both error handlers are defined, the extended version is called first. 
         */
        typedef void(*mco_error_handler_f_ex)(MCO_RET errcode, const char* file, int line);
        void mco_error_set_handler_ex(mco_error_handler_f_ex f);

        /* Heap memory manager */
        #ifdef MCO_NO_FORWARDS
            typedef void* mco_heap_h;
        #else 
            struct mco_heap_head_t_; /* heap header */
            typedef struct mco_heap_head_t_* mco_heap_h;
        #endif 
        int mco_heap_head_size(void); /* size in bytes required by heap header */
        void mco_heap_init(void* memoryptr, uint4 heapsize /* 2 ** N */,  
                           /*INOUT*/mco_heap_h h, /* caller must allocate heap head */
                           char* name);
        void mco_heap_destroy(mco_heap_h h);   /* release a semaphore  */
        uint4 mco_heap_freesize(mco_heap_h h); /* free bytes estimated */
        uint4 mco_heap_usedsize(mco_heap_h h); /* used bytes estimated */

        void* mco_malloc(mco_heap_h h, uint4 nbt);
        void* mco_calloc(mco_heap_h h, uint4 num, uint4 siz);
        void mco_free(mco_heap_h h, void* p);
        void* mco_realloc(mco_heap_h h, void* p, uint4 newsize);

        /* save/restore */
        /* abstract write and read streams interfaces; stream handle is a pointer to implementation-specific data */
        typedef mco_size_sig_t(*mco_stream_write)(void* stream_handle, const void* from, mco_size_t nbytes);
        typedef mco_size_sig_t(*mco_stream_read)(void* stream_handle, /*OUT*/void* to, mco_size_t max_nbytes);

        /* save the db content to the output stream */
        MCO_RET mco_db_save(void* stream_handle, mco_stream_write output_stream_writer, mco_db_h db);

        /* create a db instance and load the content from the input stream - instead of mco_db_open() */
        MCO_RET mco_db_load(void* stream_handle, mco_stream_read input_stream_reader, const char* db_name, mco_dictionary_h dict,
                        mco_device_t *devices, uint2 n_devices, mco_db_params_t * db_params );

        /* save the in-memory part of db content to the output stream */
        MCO_RET mco_inmem_save(void* stream_handle, mco_stream_write output_stream_writer, mco_db_h db);

        /* create a db instance and load the content from the input stream - instead of mco_db_open() */
        MCO_RET mco_inmem_load(void* stream_handle, mco_stream_read input_stream_reader, const char* db_name, mco_dictionary_h dict,
                        mco_device_t *devices, uint2 n_devices, mco_db_params_t * db_params );

        /* event handling */
        /* synchronous events: */
        typedef enum MCO_EVENT_TYPE_E_
        {
            MCO_EVENT_NEW, MCO_EVENT_UPDATE, MCO_EVENT_DELETE, MCO_EVENT_DELETE_ALL,MCO_EVENT_CHECKPOINT,MCO_EVENT_CLASS_UPDATE
        } MCO_EVENT_TYPE;

        typedef enum MCO_HANDLING_ORDER_E_
        {
            MCO_BEFORE_UPDATE, MCO_AFTER_UPDATE
        } MCO_HANDLING_ORDER;

        /* asynchronous events: handlers in different threads are signaled after commit. */
        MCO_RET mco_async_event_wait(mco_db_h dbh, int event_id);
        MCO_RET mco_async_event_release(mco_db_h dbh, int event_id);
        MCO_RET mco_async_event_release_all(mco_db_h dbh);

        typedef struct mco_runtime_info_t_
        {
            uint1 mco_version_major;
            uint1 mco_version_minor;
            uint2 mco_build_number;

            uint1 mco_size_t;
            uint1 mco_offs_t;
            uint1 uint4_supported;
            uint1 float_supported;
            uint1 mco_checklevel;
            uint1 evaluation_version;
            uint1 large_database_supported;
            uint1 collation_supported;
            uint1 heap31_supported;
            uint1 bin_serialization_supported;
            uint1 fixedrec_supported;
            uint1 statistics_supported;
            uint1 events_supported;
            uint1 save_load_supported;
            uint1 object_initialization_supported;
            uint1 direct_index_field_access_supported;
            uint1 multiprocess_access_supported;
            uint1 object_repack_supported;
            uint1 transaction_logging_supported;
            uint1 cluster_supported;
            uint1 high_availability_supported;
            uint1 ha_multicast_supported;
            uint1 ha_incremental_replication_supported;
            uint1 binary_schema_evalution_supported;
            uint1 unicode_supported;
            uint1 wchar_supported;
            uint1 recovery_supported;
            uint1 disk_supported;
            uint1 direct_pointers_supported;
            uint1 persistent_object_supported;
            uint1 xml_import_export_supported;
            uint1 user_defined_index_supported;
            uint1 multifile_supported;
            uint1 multifile_descriptor_supported;
            uint1 two_phase_commit_supported;
            uint1 rtree_supported;
            uint1 tree_based_hash;
            uint1 tmgr_mvcc_async_cleanup;
            uint1 concurent_disk_btree;
            uint1 open_cursor_goto_first;
            uint1 smart_index_insert;
            uint1 btree_leaf_lock;
            uint1 null_statistics;
            uint1 implicit_runtime_start;
            uint1 bufferized_sync_iostream;
            uint1 async_replication;
            uint1 fast_transaction_list;
            uint1 extendable_dirty_page_bitmap;
            uint1 mursiw_policy;
            uint1 sync_capabilities;
            uint1 char_comparition_policy;
            uint4 stream_buffer_size;
            uint1 max_db_instances;
            uint1 max_db_name_length;
            uint1 max_extends;
            uint4 tl_page_buffer_size;
            uint2 ha_max_replicas;
            uint4 ha_transmit_buffer_size;
            uint4 ha_syncronization_buffer_size;
            uint4 default_redo_log_limit;
            uint1 mvcc_critical_sections;
            uint1 mvcc_per_index_locks;
            uint2 con_disk_page_cache_size;
            uint1 small_con_cache_threshold;
            uint4 extendable_dirty_page_bitmap_limit;
            uint1 max_vista_sessions;
            uint1 concurrent_write_transactions;
            
#define mco_shm_supported multiprocess_access_supported
#define mco_save_load_supported save_load_supported
#define mco_disk_supported disk_supported
#define mco_multithreaded sync_capabilities
#define mco_fixedrec_supported fixedrec_supported
#define mco_xml_supported xml_import_export_supported
#define mco_stat_supported statistics_supported
#define mco_events_supported events_supported
#define mco_versioning_supported evaluation_version
#define mco_evaluation_version evaluation_version
#define mco_recovery_supported recovery_supported
#define mco_rtree_supported rtree_supported
#define mco_unicode_supported unicode_supported
#define mco_wchar_supported wchar_supported
#define mco_rtl_supported wchar_supported
#define mco_sql_supported wchar_supported
#define mco_disk_supported disk_supported
#define mco_direct_pointers direct_pointers_supported

        } mco_runtime_info_t;


        /* get eXtremeDB runtime configuration info. */
        void mco_get_runtime_info( /*OUT*/mco_runtime_info_t* pinf);

        /* global runtime options, specified per process */
        #define MCO_RT_OPTION_EXTHEAPS        0
        #define MCO_RT_OPTION_DB_SAVE_CRC     1
        #define MCO_RT_OPTION_DB_SAVE_BSE     2
        #define MCO_RT_WINDOWS_SHM_OPT        3
        #define MCO_RT_OPTION_LAST            4

        /* Windows shared memory and sync. primitives naming and security descriptor options */
        #define MCO_RT_WINDOWS_SHM_PREFIX_GLOBAL        0      /* use Global prefix. Shared objects are visible in all sessions */
        #define MCO_RT_WINDOWS_SHM_PREFIX_LOCAL         1      /* use Local prefix, Shared object are visible in current session only */
        #define MCO_RT_WINDOWS_SHM_PREFIX_SESSIONS      2      /* Vista sessions fix */
        #define MCO_RT_WINDOWS_SHM_PREFIX_NONE          3      /* Default, no prefix */
        #define MCO_RT_WINDOWS_SHM_PREFIX_MASK          3

        #define MCO_RT_WINDOWS_SHM_SEC_DESCR_EMPTY      0      /* every one can access */
        #define MCO_RT_WINDOWS_SHM_SEC_DESCR_NULL       4      /* default, use windows default policy */
        #define MCO_RT_WINDOWS_SHM_SEC_DESCR_SAMEUSER   8      /* only the same user can access */
        #define MCO_RT_WINDOWS_SHM_SEC_DESCR_MASK       12
        /* * Default is MCO_RT_WINDOWS_SHM_PREFIX_NONE|MCO_RT_WINDOWS_SHM_SEC_DESCR_NULL combination to make database visible and accessible 
             from only local session
           * Use MCO_RT_WINDOWS_SHM_PREFIX_GLOBAL|MCO_RT_WINDOWS_SHM_SEC_DESCR_EMPTY to make your database accessible from all sessions and 
             for all users
           * Use MCO_RT_WINDOWS_SHM_PREFIX_GLOBAL|MCO_RT_WINDOWS_SHM_SEC_DESCR_SAMEUSER to make your database accessible from all sessions 
             of the same user, ex. a service running under UserA and a desktop program running unser UserA
           * Please note MCO_RT_WINDOWS_SHM_PREFIX_GLOBAL is usable for Services only, desktops sessions are able to create databases using 
             MCO_RT_WINDOWS_SHM_PREFIX_LOCAL or MCO_RT_WINDOWS_SHM_PREFIX_NONE modes and to connect to databases opened with MCO_RT_WINDOWS_SHM_PREFIX_GLOBAL
             with matching security settings.
        */

        void mco_runtime_setoption(int option, int value);
        int  mco_runtime_getoption(int option);


        enum mco_file_open_flags
        {
            MCO_FILE_OPEN_DEFAULT = 0, 
            MCO_FILE_OPEN_READ_ONLY = 1, 
            MCO_FILE_OPEN_TRUNCATE = 2,
            MCO_FILE_OPEN_NO_BUFFERING = 4, 
            MCO_FILE_OPEN_EXISTING = 8,
            MCO_FILE_OPEN_TEMPORARY = 16,
            MCO_FILE_OPEN_FSYNC_FIX = 32
        };


       /**
         * Set transaction log parameters: 
         * A value of 0 means that corresponding parameter should not be changed.
         * Also depending on the log mode specified, some of parameters may be ignored.
         * Parameter "con" is a database connection and "params" are log parameters.
         * Returns an error code or MCO_S_OK.
         */
        MCO_RET mco_disk_set_log_params(mco_db_h con, mco_log_params_t* params);

        /**
         * Repair disk database after failure.
         * If using the MVCC transaction manager, in the case of a crash, a disk database can contain
         * undeleted old versions and working copies.  Their presence will not break database consistency 
         * and doesn't prevent the normal working of an application. However, detecting such objects 
         * requires a complete scan of the database.  This is why automatic recovery doesn't perform such 
         * a repair automatically.
         * It can performed explicitly by calling this function, or by setting mvcc_auto_repair to MCO_YES 
         * in the mco_disk_open_params_t when calling mco_disk_open_ex().
	     *
         * Note that mco_disk_database_vacuum requires exclusive access to the database - no other
         * operations can be performed on the database until completion of this function.
         */
        MCO_RET mco_disk_database_vacuum(mco_db_h con);

        /**
         * Save the disk cache to the specified file
         * Parameter "con" is the database connection, "file_path" is the path to the file 
         * where the cache will be saved.
         * Returns an error code or MCO_S_OK.
         */
        MCO_RET mco_disk_save_cache(mco_db_h con, char const* file_path);

        /**
         * Load the disk cache from the specified file
         * Parameter "con" is the database connection, "file_path" is the path to the file 
         * from which the cache will be loaded
         * Returns an error code or MCO_S_OK.
         */
        MCO_RET mco_disk_load_cache(mco_db_h con, char const* file_path);

        /**
         * Reset a per-connection cache of pages.  This cache is automatically reset
         * when a transaction is committed and in case of a disconnect. 
         * But if there are many active connections with long transactions, a
         * large number of pinned pages can cause the page pool space to be exhausted.
         * In such cases caching can be explicitly reset or completely prohibited using 
         * the mco_disk_enable_connection_cache function
         * Parameter "con" is the database connection.
         * Returns an error code or MCO_S_OK.
         */
        MCO_RET mco_disk_reset_connection_cache(mco_db_h con);

        /**
         * Enable or disable the per-connection cache of pages.  This cache is automatically reset
         * when a transaction is committed and in case of a disconnect. 
         * But if there are many active connections with long live transaction
         * large number of pinned pages can cause the page pool space to be exhausted.
         * In such cases caching can be prohibited using this function or the cache
         * should be periodically reset using mco_disk_reset_connection_cache function.
         * Parameter "con" is the database connection. Parameter "enabled" is set to MCO_YES to enable 
         * caching, MCO_NO to disable caching.
         * Returns the previous status of per-connection caching.
         */
        mco_bool mco_disk_enable_connection_cache(mco_db_h con, mco_bool enabled);

        /**
         * Change the transaction commit policy for the specified database connection.
         * Parameter "con" is the database connection.  Parameter "policy" is set to MCO_COMMIT_NO_SYNC,
         * MCO_COMMIT_SYNC_FLUSH,  MCO_COMMIT_BUFFERED or MCO_COMMIT_DELAYED.
         * Returns the previous commit policy.
         */
        MCO_COMMIT_POLICY mco_disk_transaction_policy(mco_db_h con, MCO_COMMIT_POLICY policy);

        typedef struct mco_disk_cache_info_t_ { 
            mco_counter_t connection_cache_hits;
            mco_counter_t cache_hits;
            mco_counter_t cache_misses;
            mco_counter_t allocated_pages;
            mco_counter_t used_pages;
            mco_counter_t pinned_pages; /* number of pinned pages */
            mco_counter_t modified_pages; /* number of pages modified by active transactions */
            mco_counter_t dirty_pages; /* number of dirty pages */
            mco_counter_t copied_pages; /* number of copies of original pages (REDO_LOG+MCO_COMMIT_DELAYED) */
            mco_counter_t write_delayed_pages; /* number of write delayed pages */
        } mco_disk_cache_info_t;


        const mco_disk_cache_info_t* mco_disk_get_cache_info(mco_db_h con);

        /**
         * Check that there are no pinned pages in disk cache.
         * Parameter "con" is the database connection.  
         * Returns an error code or MCO_S_OK.
         */
        MCO_RET mco_disk_check_cache(mco_db_h con);

        #ifdef MCO_DEBUG_DISK_CACHE
            #define MCO_DISK_CHECK_CACHE(con) mco_disk_check_cache(con)
        #else 
            #define MCO_DISK_CHECK_CACHE(con)
        #endif 

        /**
         * Save database image.
         * Parameter "db" is the database, "stream_handle" is an output stream handle
         * and "output_stream_writer" is a user-defined function implementing the actual output stream.
         * Returns an error code or MCO_S_OK.
         */
        MCO_RET mco_disk_save(void* stream_handle, mco_stream_write output_stream_writer, mco_db_h db);

        /**
         * Load database image and open database.
         * Parameter "stream_handle" is the input stream handle, "input_stream_reader" is the
         * user-defined function implementing the actual input stream. All other parameters are
         * similar to parameters passed to function mco_db_open_dev.
         * Returns an error code or MCO_S_OK.
         */
        MCO_RET mco_disk_load(void* stream_handle, mco_stream_read input_stream_reader, const char* db_name, mco_dictionary_h dict,
                        mco_device_t *devices, uint2 n_devices, mco_db_params_t * db_params);

        /**
         * Load database image.  This method should be called BEFORE
         * mco_db_open_dev. It is necessary to call the mco_db_open_dev to be able to work with loaded database.
         * Parameter "file_path" is the path to the database description file (*.mfd), "stream_handle" is the input stream handle,
         * and "input_stream_reader" is the user-defined function implementing the actual input stream.
         * Returns an error code or MCO_S_OK.
         */
        MCO_RET mco_disk_load_file(char const* file_path, void* stream_handle, mco_stream_read input_stream_reader, mco_dictionary_h dict);

        typedef struct mco_disk_info
        {
            mco_offs_t data_file_size;
            mco_offs_t log_file_size;
            mco_offs_t used_database_size;
        } mco_disk_info_t;

        /**
         * Get information about disk usage.
         * Parameter "con" is the database connection, "info" is a handle for returned information.
         * Returns an error code or MCO_S_OK.
         */
        MCO_RET mco_disk_info(mco_db_h con, mco_disk_info_t* info);

        /**
         * Flush to the disk all changes made by committed transactions.
         * This method can be used to flush changes when the MCO_COMMIT_BUFFERED transaction policy is used.
         * Parameter "con" is the database connection.
         * Returns an error code or MCO_S_OK.
         */
        MCO_RET mco_disk_flush(mco_db_h con);

        /**
         * When using two phase commit, this function should be called before opening the database
         * after a system or application crash to confirm a possible pre-committed transaction.
         * Parameter "log_file_path" is the path to the transaction log file, "log_type" is the type of
         * log: either REDO_LOG or UNDO_LOG.
         * Returns an error code or MCO_S_OK.
         */
        MCO_RET mco_disk_confirm_transaction(char const* log_file_path, MCO_LOG_TYPE log_type);

        /**
         * When using two phase commit, this function should be called before opening the database
         * after a system or application crash to reject a possible pre-committed transaction.
         * Parameter "log_file_path" is the path to the transaction log file, "log_type" is the type of
         * log: either REDO_LOG or UNDO_LOG.
         * Returns an error code or MCO_S_OK.
         */
        MCO_RET mco_disk_reject_transaction(char const* log_file_path, MCO_LOG_TYPE log_type);

        /* Filesystem wrapper interface */
        /**
         * Structure representing abstract file interface
         */
        typedef struct mco_file
        {
            /**
             * Non zero if file supports concurrent access by multiple threads (pread/pwrite operations)
             */
            mco_bool is_reentrant;

            /**
             * Write data to the specified position in file. This function must be reentrant if "is_reentrant" is true.
             * Parameter "self" is a pointer to this structure, "offs" are offsets (positions) within the file,
             * "buf" is a buffer with data to be written, "size" is the number of bytes to be written.
             * Returns the number of bytes actually written or -1 in case of error.
             */
            mco_size_sig_t(*pwrite)(struct mco_file* self, mco_offs_t offs, void* buf, mco_size_t size);

            /**
             * Read data from the specified position in file. This function must be reentrant if "is_reentrant" is true.
             * Parameter "self" is a pointer to this structure, "offs" are offsets (positions) within the file,
             * "buf" is a buffer to receive the data, "size" is the number of bytes to be read.
             * Returns the number of bytes actually read or -1 in case of error.
             */
            mco_size_sig_t(*pread)(struct mco_file* self, mco_offs_t offs, void* buf, mco_size_t size);

            /**
             * Write data to the current poistion in file.
             * Parameter "self" is a pointer to this structure, "buf" is a buffer with data to be written, 
             * "size" is the number of bytes to be written.
             * Returns the number of bytes actually written or -1 in case of error.
             */
            mco_size_sig_t(*write)(struct mco_file* self, void* buf, mco_size_t size);

            /**
             * Set current poisiton in the file.
             * Parameter "self" is a pointer to this structure, "pos" is the new current position in the file 
             * used by subsequent read/write operations.
             * Returns 0 if successful or -1 in case of error.
             */
            int(*seek)(struct mco_file* self, mco_offs_t pos);

            /**
             * Truncate file to the specified size.
             * Parameter "self" is a pointer to this structure, "size" is the new size of the file.
             * Returns 0 if successful or -1 in case of error.
             */
            int(*truncate)(struct mco_file* self, mco_offs_t size);

            /**
             * Read data from the current poistion in file.
             * Parameter "self" is a pointer to this structure, "buf" is a buffer to receive the data, 
             * "size" is the number of bytes to be read.
             * Returns the number of bytes actually read or -1 in case of error.
             */
            mco_size_sig_t(*read)(struct mco_file* self, void* buf, mco_size_t size);

            /**
             * Flush data from OS file system buffers to the disk.
             * Parameter "self" is a pointer to this structure.
             * Returns 0 if successful or -1 in case of error.
             */
            int(*flush)(struct mco_file* self);

            /**
             * Get the size of the file.
             * Parameter "self" is a pointer to this structure, "length" is the address of a 
             * variable to receive the file size. 
             * Returns 0 if successful or -1 in case of error.
             */
            int(*size)(struct mco_file* self, mco_offs_t* length);

            /**
             * Close the file.
             * Parameter "self" is a pointer to this structure.
             * Returns 0 if successful or -1 in case of error.
             */
            int(*close)(struct mco_file* self);
        } mco_file_t, * mco_file_h;


        /* direct structs helpers */
        #define  structsz(n)    ((unsigned int)sizeof(n))
        #define  fieldsz(s,f)   ((unsigned int)sizeof(((s*)0)->f))
        #define  fieldoffs(s,f) ((unsigned int)(&((s*)0)->f))
        #define  alignsz(s,n) (((s)+(n)-1)&(~(n-1)))
	
	    /* Enum helpers */
        #define _read_enum_(NUM,esz,etype,val,of1,of2) do{\
             uint##NUM tval = (uint##NUM)val;\
             res =mco_w_b##NUM##_get2((mco_objhandle_h) handle,of1,of2,&tval);\
             val = (etype)tval;\
        }while(0)

        #define _read_enum(esz,etype,val,of1,of2) do{\
            switch(esz)\
            {\
            case 1:\
                _read_enum_(1,esz,etype,val,of1,of2);\
    	        break;\
            case 2:\
                _read_enum_(2,esz,etype,val,of1,of2);\
    	        break;\
            case 4:\
                _read_enum_(4,esz,etype,val,of1,of2);\
                break;\
            default:\
                return MCO_E_UNSUPPORTED;\
                break;\
            }\
        }while (0)

        #define _write_enum_(NUM,esz,val,of1,of2,iaw) do{\
            uint##NUM tval = (uint##NUM)val;\
            res =mco_w_b##NUM##_put2((mco_objhandle_h) handle,of1,of2,iaw,tval);\
        }while(0)

        #define _write_enum(esz,val,of1,of2,iaw) do{\
            switch(esz)\
            {\
            case 1:\
            _write_enum_(1,esz,val,of1,of2,iaw);\
            break;\
            case 2:\
            _write_enum_(2,esz,val,of1,of2,iaw);\
            break;\
            case 4:\
            _write_enum_(4,esz,val,of1,of2,iaw);\
            break;\
            default:\
            return MCO_E_UNSUPPORTED;\
            break;\
            }\
        }while (0)


        #define _write_enum_ev_(NUM,esz,val,of1,of2,iaw,evt) do{\
            uint##NUM tval = (uint##NUM)val;\
            res =mco_w_b##NUM##_put_ev2((mco_objhandle_h) handle,of1,of2,iaw,tval,evt);\
        }while(0)

        #define _write_enum_ev(esz,val,of1,of2,iaw,evt) do{\
            switch(esz)\
            {\
            case 1:\
            _write_enum_ev_(1,esz,val,of1,of2,iaw,evt);\
            break;\
            case 2:\
            _write_enum_ev_(2,esz,val,of1,of2,iaw,evt);\
            break;\
            case 4:\
            _write_enum_ev_(4,esz,val,of1,of2,iaw,evt);\
            break;\
            default:\
                return MCO_E_UNSUPPORTED;\
            break;\
            }\
        }while (0)

        #define _set_enum(pext,NUM,fname) do{\
        pext->field_type =( NUM >= 4)?3:NUM; \
        if (pext->field_type == 3) pext->v.u4 = fname; \
        else if (pext->field_type == 2) pext->v.u2 = fname; \
        else pext->v.u1 = fname; \
        }while(0)

        /* check level control */
        #define MCO_CHECKS_F_USERLEVEL   1
        #define MCO_CHECKS_F_INTERNAL    2
        #define MCO_CHECKS_F_EXTENSIVE   4
        #define MCO_CHECKS_F_TEMPORARY   8
        #define MCO_CHECKS_F_PINS        0x10
     
        MCO_RET mco_check_get_level( unsigned int * checks_mask );
        MCO_RET mco_check_set_level( unsigned int checks_mask );

        mco_bool mco_db_recovery_required(char const* log_file_path);

        typedef enum mco_alloc_callback_threshold_kind_t {
            MCO_ALLOC_PERCENT_USED,
            MCO_ALLOC_FREE_LEFT,
            MCO_ALLOC_DELTA_USED,
            MCO_ALLOC_USED
        } mco_alloc_callback_threshold_kind_t;

        typedef void (*mco_alloc_callback_t)(mco_db_h db, mco_offs_t used);

        void mco_register_alloc_callback(mco_db_h db,
                                         mco_alloc_callback_t callback,
                                         mco_alloc_callback_threshold_kind_t threshold_kind,
                                         mco_offs_t threshold_value);

        void mco_register_disk_alloc_callback(mco_db_h db,
                                              mco_alloc_callback_t callback,
                                              mco_alloc_callback_threshold_kind_t threshold_kind,
                                              mco_offs_t threshold_value);


        MCO_RET mco_copy_handle(mco_db_h db, MCO_Hf* dst, MCO_Hf* src);
        MCO_RET mco_is_object_deleted( MCO_Hf* object_handle );

        #ifdef __cplusplus
        }
    #endif 

#endif
